package com.miyake.loveviewweb.server;

import java.util.ArrayList;
import java.util.List;

import org.slim3.datastore.Datastore;

import com.miyake.loveviewweb.shared.model.DataColumnBody;
import com.miyake.loveviewweb.shared.model.DataColumnModel;
import com.miyake.rest.DataColumn;

public class DataColumnConverter {
    public List<DataColumnModel> webToModel(List<DataColumn> columns) {
        List<DataColumnModel> ret = new ArrayList<DataColumnModel>();
        for (DataColumn dataColumn : columns) {
            DataColumnModel model = new DataColumnModel();
            model.setHeader(dataColumn.getHeader());
            model.setValue(dataColumn.getDataArray());
            ret.add(model);
        }
        return ret;
        
    }
    
    public List<DataColumn> modelToWeb(List<DataColumnModel> columns) {
        List<DataColumn> ret = new ArrayList<DataColumn>();
        for (DataColumnModel dataColumnModel : columns) {
            DataColumn dataColumn = new DataColumn();
            dataColumn.setDataArray(Datastore.get(DataColumnBody.class, dataColumnModel.getBodyKey()).getValue());
            dataColumn.setHeader(dataColumnModel.getHeader());
            ret.add(dataColumn);
        }
        return ret;
        
    }
}
